﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMA.GENTEv1;
using Telerik.Web.UI;

public partial class Protegidos_Empresas_GENTE_Emp : System.Web.UI.MasterPage
{
    protected const int menuAba = 1;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CarregaMenu();
        }

        RadPanelItem clickedItem = RadPanelBar1.FindItemByUrl(Request.Url.PathAndQuery);

        if (clickedItem != null)
        {
            clickedItem.ExpandParentItems();
            ShowPath(clickedItem);
        }
    }

    protected void CarregaMenu()
    {
        SMA.GENTEv1.Menu menu = new SMA.GENTEv1.Menu();
        List<SMA.GENTEv1.Menu> listMenu = new List<SMA.GENTEv1.Menu>();

        listMenu = menu.SelectAba(menuAba);

        RadPanelBar1.DataTextField = "NomeMenu";
        RadPanelBar1.DataNavigateUrlField = "Url";
        RadPanelBar1.DataFieldID = "IdMenu";
        RadPanelBar1.DataFieldParentID = "IdPai";
        RadPanelBar1.DataValueField = "IdMenu";

        RadPanelBar1.DataSource = listMenu;
        RadPanelBar1.DataBind();
    }

    private void ShowPath(RadPanelItem clickedItem)
    {
        foreach (RadPanelItem childItem in clickedItem.PanelBar.GetAllItems())
        {
            childItem.CssClass = "";
        }

        clickedItem.CssClass = "rpSelected";
    }
}
